package com.lanou3g.hw0420.socket;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.Socket;

/**
 * Created by dllo on 18/4/21.
 */
public class ReadThread extends Thread {
    private Socket socket;
    public ReadThread(Socket socket){
        this.socket=socket;
    }

    @Override
    public void run() {
        BufferedReader reader=null;
        try {
            InputStream is = socket.getInputStream();
            reader=new BufferedReader(new InputStreamReader(is));
            String line="";
            while ((line=reader.readLine())!=null){
                System.out.println(line);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            if (reader!=null){
                try {
                    reader.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
